package com.kjtpay.design_pattern.visitor;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.kjtpay.design_pattern.R;
import com.kjtpay.design_pattern.template_method.TemplateMethodActivity;

public class VisitorActivity extends AppCompatActivity {

    public static void launch(Context context) {
        if (null != context) {
            Intent intent = new Intent();
            intent.setClass(context, VisitorActivity.class);
            if (!(context instanceof Activity)) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            }
            context.startActivity(intent);
        }
    }

    TextView textViewConclusion;
    ObjectStructure objectStructure;
    Man man;
    Woman woman;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_visitor);
        setTitle("访问者模式");

        textViewConclusion = findViewById(R.id.textViewConclusion);

        // 数据结构，Element，是固定的，可以一次性准备好
        objectStructure = new ObjectStructure();
        man = new Man();
        woman = new Woman();
        objectStructure.attach(man);
        objectStructure.attach(woman);
    }

    public void onSuccessClick(View view) {
        Success success = new Success();
        textViewConclusion.setText(objectStructure.display(success));
    }

    public void onFailingClick(View view) {
        Failing failing = new Failing();
        textViewConclusion.setText(objectStructure.display(failing));
    }

    public void onAmativenessClick(View view) {
        Amativeness amativeness = new Amativeness();
        textViewConclusion.setText(objectStructure.display(amativeness));
    }

    public void onMarriageClick(View view) {
        Marriage marriage = new Marriage();
        textViewConclusion.setText(objectStructure.display(marriage));
    }
}